﻿@model QAS.Nekorama.Models.EditAnswerModel
@using QAS.Nekorama.Common
@using System.Globalization
@using System.Threading
@using Resources

<link href="~/Content/jquery-te-1.4.0.css" rel="stylesheet" />
<script src="~/Scripts/jquery-te-1.4.0.min.js"> </script>
@{if (Session["culture"] == null)
    {
        Session["culture"] = "en-US";
        Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US");
    }
    else
    {
        Thread.CurrentThread.CurrentUICulture = new CultureInfo(Session["culture"].ToString());
  }}
@using (Html.BeginForm("EditAnswer", "Question", FormMethod.Post, new { @id = "submitanswerform" }))
{
    @Html.ValidationSummary(true)

    <div class="editor-field" style="width: 700px;">
        @Html.TextAreaFor(model => model.Content, new { @class = "jqte-edit validate[required]", 
            @id = "edit-answer-content", wrap = "hard", style = "word-wrap: break-word"})
        @Html.ValidationMessageFor(model => model.Content)
    </div>
    <div style="margin-bottom: 10px;">
        @Html.TextBoxFor(model => model.EditReason, null, new { @placeholder = QAS_Nekorama.ENTER_EDIT_REASON, 
            @style = "width:695px; height: 25px; border: 1px solid #e8e8e8;" })
    </div><div id="hidethis">
        @Html.HiddenFor(m => m.AnswerID)
        @Html.HiddenFor(m => m.ModifiedUser)
    </div>
    <div>
        @Html.ActionLink(QAS_Nekorama.SAVE, null, null, new { @class = "save-btn", onclick = "editanswer(event);", style = "width: 90px;" })
    </div>
}

<script>
    $('.jqte-edit').jqte();
    var jqteStatus = true;
    $(".status").click(function () {
        jqteStatus = jqteStatus ? false : true;
        $('.jqte_editor').jqte({ "status": jqteStatus });
    });
    $(document).ready(function () {
        $("#submitanswerform").validationEngine('attach', { promptPosition: "bottomLeft", scroll: false });
        $(".jqte_editor").blur(function () {
            $("#edit-answer-content").addClass("validate[[required],min[30]]");
        });
    });
    function editanswer(event) {
        event.preventDefault();
        var content = $("#edit-answer-content").val();
        content = content.replace(/&nbsp;/g, "");
        if (content.trim().length < @Constants.ASWER_CONTENT_MINIMUM) {
            $("#submitanswerform > .editor-field").validationEngine('showPrompt', 
                '@Messages.ANSWER_CONTENT_LENGTH', 'error', 'bottomLeft', true);
            event.preventDefault();
            return false;
        } else {
            $("#edit-answer-content").val(content);
            $(".jqte_editor").removeClass("validate[[required],min[30]]");
            $(".jqte_editor").validationEngine('hideAll');
            document.getElementById('submitanswerform').submit();
        }
    }
</script>
